package com.raymond.server.impl;

import com.alibaba.fastjson.JSONObject;
import com.raymond.bean.SysUser;
import com.raymond.dao.UserDao;
import com.raymond.server.UserServer;
import com.raymond.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * user接口实现
 *
 * @author :  raymond
 * @version :  1.0
 * @date :  2019/7/23
 */
@Component
public class UserServerImpl implements UserServer {
    private final UserDao userDao;

    public UserServerImpl(UserDao userDao) {
        this.userDao = userDao;
    }


    @Override
    public String findUser() {
        List<SysUser> sysUserList = userDao.findAll();
        return JSONObject.toJSONString(new Result(sysUserList));
    }

    @Override
    public String addUser(String content) {
        SysUser user = JSONObject.parseObject(content, SysUser.class);
        userDao.save(user);
        return JSONObject.toJSONString(new Result());
    }

    @Override
    public String batchInsert(String user) {
        List<SysUser> sysUserList = JSONObject.parseArray(user, SysUser.class);
        userDao.saveAll(sysUserList);
        return JSONObject.toJSONString(new Result());
    }
}
